<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        body{
            text-align:center;
        }
        canvas {
            border: 1px solid #000;

        }
    </style>
</head>
<body>
    <canvas id="can" width="500" height="500"></canvas>
</body>
<script>
    var can=document.getElementById('can');
    var ctx=can.getContext('2d');

    //坐标轴距离画布上右下左的边距
    var padding={
        top:10,
        right:10,
        bottom:10,
        left:10
    }
    //坐标轴中箭头的宽高
    var arrow={
        width:10,
        height:20
    }
    //求顶点坐标
    var vertexTop={
        x:padding.left,
        y:padding.top
    }

    //原点坐标
    var origin={
        x:padding.left,
        y:can.height-padding.bottom
    }
    var vertexRight={
        x:can.width-padding.right,
        y:can.height-padding.bottom
    }
    //画坐标轴中的两条线
    ctx.moveTo(vertexTop.x,vertexTop.y);
    ctx.lineTo(origin.x,origin.y);
    ctx.lineTo(vertexRight.x,vertexRight.y);
    ctx.stroke();
    //上画箭头
    ctx.beginPath();
    ctx.moveTo(vertexTop.x,vertexTop.y);
    ctx.lineTo(vertexTop.x-arrow.width/2,vertexTop.y+arrow.height);
    ctx.lineTo(vertexTop.x,vertexTop.y+arrow.height/2);
    ctx.lineTo(vertexTop.x+arrow.width/2,vertexTop.y+arrow.height);
    ctx.closePath();
    ctx.fill();
    //右箭头
    ctx.beginPath();
    ctx.moveTo(vertexRight.x,vertexRight.y);
    ctx.lineTo(vertexRight.x-arrow.height,vertexRight.y-arrow.width/2);
    ctx.lineTo(vertexRight.x-arrow.height/2,vertexRight.y);
    ctx.lineTo(vertexRight.x-arrow.height,vertexRight.y+arrow.width/2);
    ctx.closePath();
    ctx.fill();

    //任一点
//    ctx.fillRect(origin.x+100,origin.y-100,5,5);

    //多个点
   /* var points= [[10,10],[20,65],[85,96],[100,364],[322,50]];
    points.forEach(function(arr,index){
        ctx.fillRect(origin.x+arr[0],origin.y-arr[1],6,6);
    });
    //在坐标轴中根据点的坐标画折现
    ctx.beginPath();
    points.forEach(function(arr,index){
        ctx.lineTo(origin.x+arr[0]+3,origin.y-arr[1]+3,6,6);
    });
        ctx.stroke();*/

    var data=[10,52,100,12,54,54,52,69,52,2];
    data.forEach(function(val,index){
        ctx.fillRect(origin.x+index*20-2,origin.y-val-2,4,4)
    });
    ctx.beginPath();
    data.forEach(function(val,index){
        ctx.lineTo(origin.x+index*20,origin.y-val,4,4)
    });
    ctx.stroke();




</script>
</html>